<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <!-- 引入react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- 引入react-dom,用于支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 引入babel,用于将jsx转换为js -->
  <script src="../js/babel.min.js"></script>

  <body>
    <!-- 容器 -->
    <div id="app"></div>
  </body>

  <script type="text/babel">
    /*
    1.高阶函数：接受的参数是一个函数或者它的返回值是函数

    2.函数柯里化：通过函数调用继续返回函数的形式，实现多次接受参数最后统一处理的函数编码形式
     */

    class Login extends React.Component {
      state = {
        username: "",
        password: "",
      };

      saveFormData = (dateType) => {
        return (e) => {
          this.setState({ [dateType]: e.target.value });
        };
      };

      handleSubmit = (e) => {
        e.preventDefault();
        const { username, password } = this.state;
        alert(`你输入的用户名是${username},密码是${password}`);
      };

      render() {
        return (
          <form action="" onSubmit={this.handleSubmit}>
            <div>
              用户名：
              <input
                type="text"
                onChange={this.saveFormData("username")}
                name="username"
              />
            </div>
            <div>
              密码：
              <input
                type="password"
                onChange={this.saveFormData("password")}
                name="password"
              />
            </div>
            <div>
              <button>登录</button>
            </div>
          </form>
        );
      }
    }

    ReactDOM.render(<Login />, document.getElementById("app"));
  </script>
</html>
